import createAxios from '/@/utils/axios'

const controllerUrl = '/admin/user/'

export function index() {
    return createAxios({
        url: controllerUrl + 'index',
        method: 'post',
    })
}

/**
 * 登录，get在登录前测试能不能联通服务器，post真正登录
 * @param method
 * @param params
 */
export function login(method: 'get' | 'post', params: object = {}): ApiPromise {
    localStorage.clear()
    sessionStorage.clear()
    return createAxios({
        url: controllerUrl + 'login',
        data: params,
        method: method,
    }) as ApiPromise
}

export function logout() {
    // const adminInfo = useAdminInfo()
    return createAxios({
        url: controllerUrl + 'logout',
        method: 'GET',
        // data: {
        //     refresh_token: adminInfo.getToken('refresh'),
        // },
    }).then(() => {
        // 清除令牌缓存
        localStorage.clear()
        sessionStorage.clear()
    })
}
